package com.nanhai.buddhist.college.module.study.controller.admin.studyadditionalcourses;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

import com.nanhai.buddhist.college.framework.excel.core.util.ExcelUtils;

import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import static com.nanhai.buddhist.college.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.nanhai.buddhist.college.module.study.controller.admin.studyadditionalcourses.vo.*;
import com.nanhai.buddhist.college.module.study.dal.dataobject.studyadditionalcourses.StudyAdditionalCoursesStudentDO;
import com.nanhai.buddhist.college.module.study.convert.studyadditionalcourses.StudyAdditionalCoursesStudentConvert;
import com.nanhai.buddhist.college.module.study.service.studyadditionalcourses.StudyAdditionalCoursesStudentService;

@Api(tags = "管理后台 - 学生选课")
@RestController
@RequestMapping("/study/additional-courses-student")
@Validated
public class StudyAdditionalCoursesStudentController {

    @Resource
    private StudyAdditionalCoursesStudentService additionalCoursesStudentService;






//    @PutMapping("/update")
//    @ApiOperation("更新学生选课")
//    @PreAuthorize("@ss.hasPermission('study:additional-courses-student:update')")
//    public CommonResult<Boolean> updateAdditionalCoursesStudent(@Valid @RequestBody StudyAdditionalCoursesStudentUpdateReqVO updateReqVO) {
//        additionalCoursesStudentService.updateAdditionalCoursesStudent(updateReqVO);
//        return success(true);
//    }

    @DeleteMapping("/delete")
    @ApiOperation("删除学生选课")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('study:additional-courses-student:delete')")
    public CommonResult<Boolean> deleteAdditionalCoursesStudent(@RequestParam("id") String id) {
        additionalCoursesStudentService.deleteAdditionalCoursesStudent(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得学生选课")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('study:additional-courses-student:query')")
    public CommonResult<StudyAdditionalCoursesStudentRespVO> getAdditionalCoursesStudent(@RequestParam("id") String id) {
        StudyAdditionalCoursesStudentDO additionalCoursesStudent = additionalCoursesStudentService.getAdditionalCoursesStudent(id);
        return success(StudyAdditionalCoursesStudentConvert.INSTANCE.convert(additionalCoursesStudent));
    }

    @GetMapping("/list")
    @ApiOperation("获得学生选课列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('study:additional-courses-student:query')")
    public CommonResult<List<StudyAdditionalCoursesStudentRespVO>> getAdditionalCoursesStudentList(@RequestParam("ids") Collection<String> ids) {
        List<StudyAdditionalCoursesStudentDO> list = additionalCoursesStudentService.getAdditionalCoursesStudentList(ids);
        return success(StudyAdditionalCoursesStudentConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得学生选课分页")
    @PreAuthorize("@ss.hasPermission('study:additional-courses-student:query')")
    public CommonResult<PageResult<StudyAdditionalCoursesStudentRespVO>> getAdditionalCoursesStudentPage(@Valid StudyAdditionalCoursesStudentPageReqVO pageVO) {
        PageResult<StudyAdditionalCoursesStudentDO> pageResult = additionalCoursesStudentService.getAdditionalCoursesStudentPage(pageVO);
        return success(StudyAdditionalCoursesStudentConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出学生选课 Excel")
    @PreAuthorize("@ss.hasPermission('study:additional-courses-student:export')")
    @OperateLog(type = EXPORT)
    public void exportAdditionalCoursesStudentExcel(@Valid StudyAdditionalCoursesStudentExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<StudyAdditionalCoursesStudentDO> list = additionalCoursesStudentService.getAdditionalCoursesStudentList(exportReqVO);
        // 导出 Excel
        List<StudyAdditionalCoursesStudentExcelVO> datas = StudyAdditionalCoursesStudentConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "学生选课.xls", "数据", StudyAdditionalCoursesStudentExcelVO.class, datas);
    }



    @PostMapping("/auditAdditionalCourses")
    @ApiOperation("审核选课")
    public CommonResult<String> auditAdditionalCourses(@Valid @RequestBody StudyAdditionalCoursesStudentAuditReqVO createReqVO) {
        return success(additionalCoursesStudentService.auditAdditionalCoursesByStudent(createReqVO));
    }


}
